/*
Apr 30, 2013
Movement.java
Erich Hauck
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Player extends JPanel
{  
   private ImageIcon imageArray[];
   private Image pl;
   private int width;
   Rectangle playerBox;
   private int height;
   private int  /*how many pictures*/totalFrames = 25 ,/*frame you are on*/ currentFrame =0;
   
   //creates the placement for the shape
   private int x=300, y=500, vx=0, vy=0;
   //creates for the movement
   boolean moveUp, moveDown, moveLeft, moveRight;
   


   public Player()
   {

      //creates array for images
     
      imageArray = new ImageIcon[totalFrames];
      
      
      //adds every image icon in order to the array
      for (int i =0; i<imageArray.length-21;i++)
      {
         imageArray[i] = new ImageIcon("b"+(i+1)+".png");
         
      }
      for (int i =3; i<imageArray.length-18;i++)
      {
         imageArray[i] = new ImageIcon("f"+(i-2)+".png");
         
      }
      for (int i =6; i<imageArray.length-15;i++)
      {
         imageArray[i] = new ImageIcon("l"+(i-5)+".png");
         
      }
      for (int i =9; i<imageArray.length-12;i++)
      {
         imageArray[i] = new ImageIcon("r"+(i-8)+".png");
         
      }
      for (int i =12; i<imageArray.length-9;i++)
      {
         imageArray[i] = new ImageIcon("ur"+(i-11)+".png");
         
      }
      for (int i =15; i<imageArray.length-6;i++)
      {
         imageArray[i] = new ImageIcon("ul"+(i-14)+".png");
         
      }
      for (int i =18; i<imageArray.length-3;i++)
      {
         imageArray[i] = new ImageIcon("dr"+(i-17)+".png");
         
      }
      for (int i =21; i<imageArray.length;i++)
      {
         imageArray[i] = new ImageIcon("dl"+(i-20)+".png");
         
      }
     
      pl = imageArray[currentFrame].getImage();
      
      
      //gets height and width of image
      width = pl.getWidth(null);
      height = pl.getHeight(null);
      playerBox = new Rectangle(x, y+8, width-15, height-8);

   }
   

   
   
//gets the bounds of the player
  public Rectangle getBounds() 
  {
      return playerBox;
  }
  public void changeBounds()
  {
     playerBox = new Rectangle(x, y+8, width-15, height-8);
  }
  
  //gets the image of the character
   public Image character()
   {
      return pl;
   }
   //gets the x and y values
   public int getX()
   {
      return x;
   }
   
   public int getY()
   {
      return y;
   }
   public void setX(int xin)
   {
    x = xin;  
   }
   public void setY(int yin)
   {
      y=yin;
   }
   public int getWidth()
   {
      return width;
   }
   public int getHeight()
   {
      return height;
   }
//sets the movement
   public void setMoveUp(boolean in)
   {
      moveUp=in;
   }
   public void setMoveDown(boolean in)
   {
      moveDown=in;
   }
   public void setMoveLeft(boolean in)
   {
      moveLeft=in;
   }
   public void setMoveRight(boolean in)
   {
      moveRight = in;
   }
   
   //gets movement
   public boolean getUp()
   {
      return moveUp;
   }
   public boolean getDown()
   {
      return moveDown;
   }
   public boolean getLeft()
   {
      return moveLeft;
   }
   public boolean getRight()
   {
      return moveRight;
   }
   
   //alters the frames
   public void setFrame(int input)
   {
      currentFrame = input;
   }
   public int getFrame()
   {
      return currentFrame;
   }
   public void changeFrame()
   {
      currentFrame++;
   }
   public void changeSprite()
   {
      pl = imageArray[currentFrame].getImage();
   }
   //Movement commands, alters the placement of x and y
   public void move()
   {
      x+=vx;
      y+= vy;
   }
   public void up()
   {
      vy = -1;
     
   }
   
   public void down()
   {
      vy = 1;
     
   }
   public void left()
   {
      vx = -1;
      
   }
   public void right()
   {
      vx=1;
     
   }
   
   public void upRight()
   {
      vx=1;
      vy=-1;
   }
   
   public void downRight()
   {
      vx=1;
      vy=1;
   }
   
   public void upLeft()
   {
      vx=-1;
      vy=-1;
   }
   public void downLeft()
   {
      vx = -1;
      vy = 1;
   }
   public void stop()
   {    
      vx=0;
      vy=0;
    
   }
   public void stopY()
   {
      vy=0;
   }
   public void stopX()
   {
      vx=0;
   }
   

}
